nnoremap <silent> <leader>gs <ESC>:Git status<CR>
nnoremap <silent> <leader>gc <ESC>:Git commit<CR>
nnoremap <silent> <leader>gP <ESC>:Git push<CR>
nnoremap <silent> <leader>gp <ESC>:Git pull<CR>

if has('nvim')
lua << EOF
require('gitsigns').setup{
	on_attach = function(bufnr)
		local gs = package.loaded.gitsigns

		local function map(mode, l, r, opts)
			opts = opts or {}
			opts.buffer = bufnr
			vim.keymap.set(mode, l, r, opts)
		end

		map('n', ']c', function()
			if vim.wo.diff then return ']c' end
			vim.schedule(function() gs.next_hunk() end)
			return '<Ignore>'
		end, {expr=true})

		map('n', '[c', function()
			if vim.wo.diff then return '[c' end
			vim.schedule(function() gs.prev_hunk() end)
			return '<Ignore>'
		end, {expr=true})

		map('n', '<leader>hp', gs.preview_hunk)
		map('n', '<leader>hb', function() gs.blame_line{full=true} end)

		map({'o', 'x'}, 'ih', ':<C-U>Gitsigns select_hunk<CR>')
	end,
}
EOF
endif
